<?php
class Theme extends Model {
	
	private static $table_name = 'THEME';
	
	public function __construct($themeData) {
		parent::__construct();
		$this->values = $themeData;
	}
	
	public static function getAllThemes() {
		$dbConnection = PDOConnection::getInstance();
		$requete= $dbConnection->query("SET NAMES UTF8;");
		
		$requete=$dbConnection->prepare("	SELECT IDTHEME, NOMTHEME 
											FROM ".self::$table_name.
											" ORDER BY NOMTHEME ASC;"
										);
		$requete->execute();
		$i=0;
		$data = array();
		while($tab = $requete->fetch(PDO::FETCH_ASSOC)) {
			$data[$i]=new Theme($tab);
			$i++;
		}
		return $data;
	}
	
	public static function getTheme($id) {
		$dbConnection = PDOConnection::getInstance();
		$requete=$dbConnection->prepare("	SELECT IDTHEME, NOMTHEME 
											FROM ".self::$table_name."
											WHERE IDTHEME=:idtheme");
		$requete->execute(array('idtheme'=>$id));
		$i=0;
		$data = array();
		while($tab = $requete->fetch(PDO::FETCH_ASSOC)) {
			$data[$i]=new Theme($tab);
			$i++;
		}
		return $data;
	}
	
	public function getIdTheme() { return $this->values['IDTHEME']; }
	public function getNomTheme() { return $this->values['NOMTHEME']; }
}